package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.ChargeStationInfoMapper;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.enums.AppHttpCodeEnum;
import com.zhentao.model.pojo.core.ChargeStationInfo;
import com.zhentao.model.pojo.core.ChargingStationCollection;
import com.zhentao.model.pojo.user.ChargeUser;
import com.zhentao.service.ChargingStationCollectionService;
import com.zhentao.mapper.ChargingStationCollectionMapper;
import com.zhentao.user.ChargeUserThreadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author 31919
* @description 针对表【charging_station_collection】的数据库操作Service实现
* @createDate 2024-12-24 13:54:44
*/
@Service
public class ChargingStationCollectionServiceImpl extends ServiceImpl<ChargingStationCollectionMapper, ChargingStationCollection>
    implements ChargingStationCollectionService{
    @Autowired
    private ChargeStationInfoMapper chargeStationInfoMapper;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public ResponseResult getMyCollection() {
        ChargeUser user = ChargeUserThreadUtils.getChargeUserThreadLocal();
        if (user == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN);
        }
        List<ChargingStationCollection> list = list(Wrappers.<ChargingStationCollection>lambdaQuery().eq(ChargingStationCollection::getUserId, user.getId()));
        List<Integer> chargeStationIds = list.stream().map(ChargingStationCollection::getChargeStationId).collect(Collectors.toList());
        List<ChargeStationInfo> chargeStationInfos = chargeStationInfoMapper.selectBatchIds(chargeStationIds);
        return ResponseResult.okResult(chargeStationInfos);
    }
}




